package models

import (
	"go.mongodb.org/mongo-driver/bson/primitive"
	"go.mongodb.org/mongo-driver/mongo"
)

type User struct {
	ID       primitive.ObjectID `json:"id" bson:"_id" validate:"omitempty,required"`
	Username string             `json:"username" bson:"username" validate:"required,alphanum,min=3,max=20"`
	Password string             `json:"password" bson:"password" validate:"required"`
	Email    string             `json:"email" bson:"email" validate:"omitempty,email"`
	Phone    string             `json:"phone" bson:"phone" validate:"omitempty,len=11"`
	Address  string             `json:"address" bson:"address" `
	Age      int                `json:"age" bson:"age" validate:"omitempty,gte=0,lte=120"`
	Gender   int                `json:"gender" bson:"gender" validate:"omitempty,gte=0,lte=2"` // 0: 未知，1: 男，2: 女
	//role 只能是 admin, user, guest 中的一个或多个，用逗号分隔
	//role 可以是 admin, user, guest 中的一个或多个，用逗号分隔

	Role     []string `json:"role" bson:"role" validate:"omitempty"`                 // `json:"role" bson:"role" validate:"omitempty,dive,oneof=admin user guest"     //  "admin", "user", "guest"
	Status   int      `json:"status" bson:"status" validate:"omitempty,gte=0,lte=5"` // 0: 正常，1: 禁用，2: 封禁，3: 注销，4: 未验证，5: 已验证
	Avatar   string   `json:"avatar" bson:"avatar"`
	LoginAt  int64    `json:"login_at" bson:"login_at"`
	LogoutAt int64    `json:"logout_at" bson:"logout_at"`
}

type UserRepository struct {
	*BaseRepository[User]
}

func NewUserRepository(db *mongo.Database, collectionName string) *UserRepository {
	return &UserRepository{
		BaseRepository: NewBaseRepository[User](db, collectionName), // 替换为你的集合名称
	}
}

// 用户登录
// func (r *UserRepository) Login(username string, password string) (*User, error) {
// 	query := bson.M{"username": username, "password": password}
// 	result, err := r.FindOne(query)
// 	if err != nil {
// 		return nil, err
// 	}
// 	return result, nil
// }
